<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var obj = {
      a: 10
    }
    /*
    Object.defineProperty
    定义一个对象属性：
      给这个属性添加一个
      getter 取值拦截器
      setter 赋值拦截器
    */ 
   var a = 100;
   Object.defineProperty(obj,'a', {
     get(){
      console.log('getter触发了');
      return a;
     },
     set(val){
      console.log('setter触发了', val);
      a = val;
     }
   })
   console.log(obj.a);
   obj.a = 200;
   console.log(obj.a);
  </script>
</body>
</html>